%function Landol_C_drawThrImp(thr_pre_t,thr_post_t,rt_pre_t,rt_post_t,thr_pre_ct,thr_post_ct,rt_pre_ct,rt_post_ct,thr_pre_c,thr_post_c,rt_pre_c,rt_post_c)

%colors = [211 57 33; 2 158 154]/255;
colors = [2 158 154; 255 189 7; 211 57 33]/255;

%% Near distance
% Alternating group
thr_pre_n_t = thr_pre_t(:,2:4); thr_post_n_t = thr_post_t(:,2:4);
thr_pre_f_t = thr_pre_t(:,1); thr_post_f_t = thr_post_t(:,1);

imp_near_all_t = 100*(thr_pre_n_t - thr_post_n_t)./thr_pre_n_t;
imp_near_t = mean(imp_near_all_t,2); % Significant improvement p = 0.0017
imp_far_t = 100*(thr_pre_f_t - thr_post_f_t)./thr_pre_f_t; % Significant improvement p = 0.0083

m_imp_near_t = mean(imp_near_t);
se_imp_near_t = std(imp_near_t)/sqrt(8);

m_imp_far_t = mean(imp_far_t);
se_imp_far_t = std(imp_far_t)/sqrt(8);


% Fixed group
thr_pre_n_ct = thr_pre_ct(:,2:4); thr_post_n_ct = thr_post_ct(:,2:4);
thr_pre_f_ct = thr_pre_ct(:,1); thr_post_f_ct = thr_post_ct(:,1);

imp_near_all_ct = 100*(thr_pre_n_ct - thr_post_n_ct)./thr_pre_n_ct;
imp_near_ct = mean(imp_near_all_ct,2); % Significant improvement p = 0.0100
imp_far_ct = 100*(thr_pre_f_ct - thr_post_f_ct)./thr_pre_f_ct; % Not Significant

m_imp_near_ct = mean(imp_near_ct);
se_imp_near_ct = std(imp_near_ct)/sqrt(8);

m_imp_far_ct = mean(imp_far_ct);
se_imp_far_ct = std(imp_far_ct)/sqrt(8);


% Control group
thr_pre_n_c = thr_pre_c(:,2:4); thr_post_n_c = thr_post_c(:,2:4);
thr_pre_f_c = thr_pre_c(:,1); thr_post_f_c = thr_post_c(:,1);

imp_near_all_c = 100*(thr_pre_n_c - thr_post_n_c)./thr_pre_n_c;
imp_near_c = mean(imp_near_all_c,2); % Not Significant
imp_far_c = 100*(thr_pre_f_c - thr_post_f_c)./thr_pre_f_c; % Not Significant

m_imp_near_c = mean(imp_near_c);
se_imp_near_c = std(imp_near_c)/sqrt(8);

m_imp_far_c = mean(imp_far_c);
se_imp_far_c = std(imp_far_c)/sqrt(8);

%% Draw figures


figure('color',[1 1 1])

colors2 = colors*1.2;
colors2(colors2>1) = 1;

dataF = [imp_near_t imp_far_t imp_near_ct imp_far_ct imp_near_c imp_far_c];
xaxisF = [1 2 4 5 7 8];
colorsF = repelem(colors,2,1);
colorsF2 = repelem(colors2,2,1);

for bb = 1:6
    b = bar(xaxisF(bb),mean(dataF(:,bb)));
    b.FaceColor = 'flat';
    b.LineWidth= 1;
    b.CData(1,:) = colorsF(bb,:);
    hold on
    % with marker edge
%      plot(xaxisF(bb),dataF(:,bb),'o', 'MarkerEdgeColor' ,[0 0 0], 'MarkerFaceColor' ,colorsF2(bb,:),'MarkerSize',7);
    plot(xaxisF(bb),dataF(:,bb),'o', 'MarkerEdgeColor' ,[0.7 0.7 0.7], 'MarkerFaceColor' ,colorsF2(bb,:),'MarkerSize',7);
   
    % without marker edge
%       plot(xaxisF(bb),dataF(:,bb),'o', 'MarkerEdgeColor' ,'none', 'MarkerFaceColor' ,colorsF2(bb,:),'MarkerSize',7);
% %     plot(xaxisF(bb),dataF(:,bb),'o', 'MarkerFaceColor' ,colorsF2(bb,:),'MarkerSize',7);
    hold on
    bars{bb,1} = b;
end

errorbar(xaxisF,mean(dataF),std(dataF)/sqrt(8),'ko','MarkerFaceColor',[1 1 1],'linewidth',1,'CapSize',0)
% errorbar(xaxisF,mmF,seF,'ko','MarkerFaceColor',[1 1 1],'linewidth',1,'CapSize',0)
% set(gca,'xtick',xaxisF,'xticklabel',{'Near','Far','Near','Far','Near','Far','Near','Far'},'ylim',[-32 30],'fontsize',10,'linewidth',1);
set(gca,'xtick',xaxisF,'xticklabel',{'Near','Far','Near','Far','Near','Far','Near','Far'},'ylim',[-32 30],'FontName', 'Arial','fontsize',10,'linewidth',1);
l = cell(1,3);
l{1}='Alternating'; l{2}='Fixed'; l{3}='Control';
[hLg, icons] = legend([bars{1,1},bars{3,1}, bars{5,1}],l,'location','southwest');
legend boxoff

icons = findobj(icons,'Type','patch');
% icons = findobj(icons,'Marker','none','-xor');
set(icons(1),'Vertices',[3*(icons(1).Vertices(:,1)/4) (icons(1).Vertices(:,2))]);
set(icons(2),'Vertices',[3*(icons(2).Vertices(:,1)/4) (icons(2).Vertices(:,2))]);
set(icons(3),'Vertices',[3*(icons(3).Vertices(:,1)/4) (icons(3).Vertices(:,2))]);

box off
% set(gca,'xticklabel',{'Alternating','Fixed','Control'});
ylabel('VA improvement (%)', 'FontName', 'Arial');

 set(gcf,'units','centimeters','position',[0 0 19 9])
% set(gcf,'units','centimeters','position',[0 0 11.5 9])